package Process;

/**
 * This class manages and creates a producer.
 * 
 * @author Stephen Amos, Zach Turk, Dickson Kwong
 */
public class Producer extends Process
{
	/**
	 * This is the data structure used by the producer and consumer.
	 */
	int producer_data;
	int mem_index;
	
	/**
	 * Creates a producer.
	 * @param the_id The producer ID
	 * @param the_requests The instructions in the program
	 * @param mem_index The index of the shared memory
	 */
	public Producer(int the_id, SysCall[] the_requests, int mem_index) 
	{
		super(the_id, the_requests, 0);
		the_requests[0] = SysCall.SEM_DOWN;
		the_requests[1] = SysCall.MUTEX_LOCK;
		the_requests[the_requests.length/2] = SysCall.MEM_WRITE;
		the_requests[the_requests.length - 2] = SysCall.MUTEX_UNLOCK;
		the_requests[the_requests.length - 1] = SysCall.SEM_UP;
		this.mem_index = mem_index;
	}
	
	/**
	 * Adds data to the shared data structure between the consumer
	 * and producer pair.
	 */
	public int addToData()
	{
		return producer_data++;
	}
	
	/**
	 * Returns the producer/consumer data structure.
	 * 
	 * @return The producer/consumer data structure.
	 */
	public int getList()
	{
		return producer_data;
	}
	
	public int memAddress() {
		return mem_index;
	}

}
